<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>登陆</title>
		<link rel="stylesheet" th:href="@{/manager/css/login.css}">
		<script th:src="@{/manager/js/jquery-1.4.2.min.js}"></script>
		<!--背景图片自动更换-->
		<script th:src="@{/manager/js/supersized.3.2.7.min.js}"></script>
		<script th:src="@{/manager/js/login-page/login-supersized-init.js}"></script>
		<script>
			function login(event) {
				event.preventDefault(); // 阻止表单默认提交
				$.ajax({
					dataType: "json",
					url: "/manager/manageruser/login",
					data: $('#loginForm').serialize(),
					// {
					// 	"username": $("#username").val(), // 使用 .val() 获取值
					// 	"password": $("#password").val()
					// },
					success: function (result) {
						if (result.status == 200) {
							sessionStorage.setItem('USER_NAME',result.data.username);
							sessionStorage.setItem('USER_ID',result.data.id);
							sessionStorage.setItem('USER_COMPANY_ID',result.data.commpanyid);
							location.href = "/manager/showindex"; // 成功登录后重定向
						} else {
							alert("用户名或密码错误"); // 登录失败提示
						}
					},
					error: function (xhr, status, error) {
						alert("请求失败: " + xhr.responseText); // 处理 AJAX 请求错误
					}
				});
			}
		</script>
		<script>
			// 页面加载时检查是否有错误消息并显示弹出框
			window.onload = function() {
				var loginMsg = $("#errorMessage").text();
				if (loginMsg) {
					alert(loginMsg);
				}
			};
		</script>
	</head>
	<body>
	    <span id="errorMessage" th:text="${loginMsg}" style="display: none"></span>
		<div class="login-container">
			<h1>ITANY 生活服务</h1>
			<div class="connect">
				<p>后台维护管理系统</p>
			</div>
			<form method="post" id="loginForm">
				<div>
					<input type="text" name="username" class="username" id="username" placeholder="用户名" autocomplete="off" />
				</div>
				<div>
					<input type="password" name="password" class="password" id="password" placeholder="密码" oncontextmenu="return false" onpaste="return false" />
				</div>
				<button id="submit" type="submit" onclick="login(event)">登 陆</button>
			</form>
		</div>
	</body>
</html>